﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System.Data.Entity;
using System.Linq;
using Emico.Data.Entity.Tests.Repository;
using Emico.Data.Entity.Tests.Repository.Imples;
using Emico.Data.Entity.Repository;
using Microsoft.Practices.Unity;

namespace Emico.Data.Entity.Tests
{
    [TestClass]
    public class DbTest
    {
        [TestMethod]
        public void TestCreate()
        {
            IUnityContainer container = new UnityContainer();
            TestContextConfig.Register(container);

            using (ITestContextUnitOfWork uw = container.Resolve<ITestContextUnitOfWork>())
            {                
                Simple simple = new Simple();
                simple.Columns = "Col";

                var repository = uw.GetRepository<ISimpleRepository>();
                repository.Add(simple);
                uw.Commit();
            }
        }

        //[TestMethod]
        //public void TestRead()
        //{
        //    Simple simple = new Simple { Id = 1 };
        //    var data = new Simple[] { simple }.AsQueryable();

        //    var mockSet = new Mock<DbSet<Simple>>();
        //    mockSet.As<IQueryable<Simple>>().Setup(m => m.Provider).Returns(data.Provider);
        //    mockSet.As<IQueryable<Simple>>().Setup(m => m.Expression).Returns(data.Expression);
        //    mockSet.As<IQueryable<Simple>>().Setup(m => m.ElementType).Returns(data.ElementType);
        //    mockSet.As<IQueryable<Simple>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

        //    var mockContext = new Mock<TestContext>();
        //    var mockContextWrapper = new Mock<IDbContextWrapper>();
        //    mockContextWrapper.Setup(c => c.Set<Simple>()).Returns(mockSet.Object);

        //    using (TestContextUnitOfWork uw = new TestContextUnitOfWork(mockContextWrapper.Object))
        //    {
        //        var repository = new SimpleRepository(mockContextWrapper.Object);
        //        Simple result = repository.FirstOrDefault(s => s.Id == simple.Id);
        //        Assert.AreSame(simple, result);
        //    }
        //}
    }
}
